TK!2
=v
#1
:n

:s
b
=u
=l
#1
:n
u
:v
'u1
'u2
'u3
'u4
'u5
'u6
'u7
'u8
'u9
'u10
E
#2
:n
u1
:v
2
0
-2
E
#3
:n
u2
:v
0
.5
-2
E
#4
:n
u3
:v
0
0
3
E
#5
:n
u4
:v
0
5
0
E
#6
:n
u5
:v
7
0
7
E
#7
:n
u6
:v
E
#8
:n
u7
:v
E
#9
:n
u8
:v
E
#10
:n
u9
:v
E
#11
:n
u10
:v
E
#12
:n
v
:v
'v1
'v2
'v3
'v4
'v5
'v6
'v7
'v8
'v9
'v10
E
#13
:n
v1
:v
.5
0
1
-3
1
2
E
#14
:n
v2
:v
0
-2
0
.15
0
1
E
#15
:n
v3
:v
2
0
0
-1
0
1
E
#16
:n
v4
:v
E
#17
:n
v5
:v
E
#18
:n
v6
:v
E
#19
:n
v7
:v
E
#20
:n
v8
:v
E
#21
:n
v9
:v
E
#22
:n
v10
:v
E
#23
:n
w
:v
'w1
'w2
'w3
'w4
'w5
'w6
'w7
'w8
'w9
'w10
E
#24
:n
w1
:v
E
#25
:n
w2
:v
E
#26
:n
w3
:v
E
#27
:n
w4
:v
E
#28
:n
w5
:v
E
#29
:n
w6
:v
E
#30
:n
w7
:v
E
#31
:n
w8
:v
E
#32
:n
w9
:v
E
#33
:n
w10
:v
E
#34
:n
aux
:v
'aux01
'aux02
'aux03
'aux04
'aux05
'aux06
'aux07
'aux08
'aux09
'aux10
E
=f
#1
:n
Mproduct
:c
Multiplication of two matrices
:t
Procedure
:i
A,B,C
#2
:n
Mblank
:c
Blank matrix (i.e. subordinate lists)
:t
Procedure
:i
M,n
#3
:n
Mdelete
:c
Delete matrix (i.e. subordinate lists)
:t
Procedure
:i
M
#4
:n
transpose
:c
Transposing matrix A into matrix B
:t
Procedure
:i
A,B
#1
:n
Mproduct
:z
" The procedure generates a product of two matrices defined by the master 
" lists  A  and  B  and their subordinate lists.  The resulting matrix is
" stored in lists subordinate to the master list C, which must be set up in
" advance. Also, the master list  'aux  for temporary storage of a transpose
" of  B  must be available.  The master lists  C  and  'aux  must be at least
" as long as the list B[1]. 

" The matrices  A , B  should be compatible, i.e. if  A  represents an  m x p
" matrix, B must be  p x n  and the resulting matrix is  m x n .  The number
" m  of rows of the resulting matrix is found by searching for the first
" blank among the first elements of  A[1], A[2], ... .  The number  n  of
" columns of the resulting matrix is made equal to the length of B[1] (i.e. 
" the number of columns of  B ).  Any blanks in the lists constituting the
" matrices  A  and  B  are interpreted as zero coefficients by the TK
" built-in  dot  function which is used for performing the calculations.

" Supporting functions: transpose, Mblank, Mdelete.

m:= 0
for i=1 to length(A)
   if elt(A[i],1,'blank)='blank goto M
   m:= i
next i
M:
n:= length(B[1])
call Mblank(C,n)    " error indicates missing elements in the master C
call transpose(B,'aux)
if length(A[1]) <> length('aux[1]) then error:= incompatible_dimensions
for i=1 to m
   for j=1 to n
      C[i][j]:= dot(A[i],'aux[j])
   next j
next i
call Mdelete('aux)
/E
E
#2
:n
Mblank
:z
" The procedure blanks (i.e. erases the contents) of the first  n  lists
" named in the master list  M .

for i=1 to n
   call blank(M[i])    " error indicates no listname in ith element of M
next i
/E
E
#3
:n
Mdelete
:z
" The procedure deletes subordinate lists of the master list  M  from the
" List Sheet. The master list remains intact.

for i=1 to length(M)
   call delete(M[i])    " error indicates no listname in ith element of M
next i
/E
E
#4
:n
transpose
:z
" Notation:  A  -  master list of the source matrix
"            B  -  master list of the target matrix

for j=1 to length(B)
   call blank(B[j])        " blank all B-lists
next j
for i=1 to length(A)
   Ai:= A[i]
   for j=1 to length(Ai)
      Aij:= elt(Ai,j,'blank)
      if Aij<>'blank then B[j][i]:= Aij
   next j
next i
/E
E
=r
#1
:r
call Mproduct('u,'v,'w)
#3
:r
" In this example we show the use of the library function Mproduct for
:s
C
#4
:r
" multiplying the matrices  u  and  v , and storing the result in  w .  
:s
C
#5
:r
" Press F9 and watch the result come up in the lower window.
:s
C
#7
:r
" The matrices  u  and  v  may be displayed as tables with the same names, 
:s
C
#8
:r
" and altered as required.
:s
C
=p
=t
#1
:n
u
:s
Screen
:v
Horizontal
:f
1
:r
""
:c
""
:t
"Input matrix u"
:u
#1
:l
u1
:w
8
:h
""
#2
:l
u2
:w
8
:h
""
#3
:l
u3
:w
8
:h
""
#4
:l
u4
:w
8
:h
""
#5
:l
u5
:w
8
:h
""
E
#2
:n
v
:s
Screen
:v
Horizontal
:f
1
:r
""
:c
""
:t
"Input matrix v"
:u
#1
:l
v1
:w
8
:h
""
#2
:l
v2
:w
8
:h
""
#3
:l
v3
:w
8
:h
""
E
#3
:n
w
:s
Screen
:v
Horizontal
:f
1
:r
""
:c
""
:t
"Product of matrices  u  and  v"
:u
#1
:l
w1
:w
8
:h
""
#2
:l
w2
:w
8
:h
""
#3
:l
w3
:w
8
:h
""
#4
:l
w4
:w
8
:h
""
#5
:l
w5
:w
8
:h
""
E
#4
:n
uvw
:s
Screen
:v
Horizontal
:f
1
:r
""
:c
""
:t
"Matrices u,v,w"
:u
#1
:l
u1
:w
8
:h
""
#2
:l
u2
:w
8
:h
""
#3
:l
u3
:w
8
:h
""
#4
:l
u4
:w
8
:h
""
#5
:l
u5
:w
8
:h
""
#6
:w
8
:h
""
#7
:l
v1
:w
8
:h
""
#8
:l
v2
:w
8
:h
""
#9
:l
v3
:w
8
:h
""
#10
:w
8
:h
""
#11
:l
w1
:w
8
:h
""
#12
:l
w2
:w
8
:h
""
#13
:l
w3
:w
8
:h
""
#14
:l
w4
:w
8
:h
""
#15
:l
w5
:w
8
:h
""
E
=n
=g
#1
:c
.000001
:i
10
:v
Yes
:l
60
:f
66
:m
0
:w
80
:b
Yes
:a
Yes
:r
Yes
:h
No
:t
1
:n
Yes
:d
LPT1
%Tr,f,0,1,0,1,0
%Ot,f,2,0,0,1,0>t,0,0,0,8,0>t,0,1,0,2,0
